﻿using System.Linq;
using System.Web.Mvc;
using MvcMusicStore.Models;

namespace MvcMusicStore.Controllers
{
    /// <summary>
    /// Class to respond to browser input for store page and decide action to take upon
    /// and response to return to user. This controller will support three scenarios:
    /// 1. A listing page of the music genres in the music store
    /// 2. A browse page that lists all of the music albums in a praticular genre
    /// 3. A details page that shows information about a specific music album
    /// </summary>
    public class StoreController : Controller
    {
        readonly MusicStoreEntities _storeDb = new MusicStoreEntities();

        //
        // GET: /Store/
        public ActionResult Index()
        {
            var genres = _storeDb.Genres.ToList();
            return View(genres);
        }

        //
        // GET: /Store/Browse?genre=Disco
        public ActionResult Browse(string genre)
        {
            // return new genre
            var genreModel = _storeDb.Genres.Include("Albums").Single(g => g.Name == genre);
            return View(genreModel);
        }

        //
        // GET: /Store/Details/id
        public ActionResult Details(int id)
        {
            // return new album
            var album = _storeDb.Albums.Find(id);
            return View(album);
        }
    }
}
